package com.sxt.utils;

/**
 * 求一个值得hashCode值
 * @author LU
 *
 */
public class HashFun {
	// 求hash的关键数字
	private int seed;

	public HashFun(int seed) {
		this.seed = seed;
	}

	/**
	 * 给一个值求hashcode 值
	 * @param value
	 * @return
	 */
	public int hash(String value) {
		int hash = 0 ;
		char []chars = value.toCharArray();
		if (hash == 0 && chars.length > 0) {
			char val[] = chars;
			for (int i = 0; i < chars.length; i++) {
            	hash = seed * hash + val[i]; // 运算hash 值的关键点 31：素数 7 11 19 23 29 31
            }
		}
		return hash;
	}

}
